<?php
namespace Application\Entity;


use Doctrine\ORM\Mapping as ORM;
use Application\Repository\FriendRepository;

/**
 * User
 *
 * @ORM\Entity(repositoryClass="Application\Repository\FriendRepository") @ORM\Table(name="friend")
 */
class Friend
{
    /**
     * @var integer
     *
     * @ORM\Column(name="id", type="bigint", nullable=false)
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="IDENTITY")
     */
    public $id;
    
    /**
     * @var \Provider
     *
     * @ORM\ManyToOne(targetEntity="Application\Entity\User")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="user_from_uid", referencedColumnName="uid")
     * })
     */
    public $userFrom;

     /**
     * @var \Provider
     *
     * @ORM\ManyToOne(targetEntity="Application\Entity\User")
     * @ORM\JoinColumns({
     *   @ORM\JoinColumn(name="user_to_uid", referencedColumnName="uid")
     * })
     */
    public $userTo;
    
    /**
     * @var string
     *
     * @ORM\Column(name="copter", type="boolean", nullable=true)
     */
    public $copter;
    
    /**
     * @var \DateTime
     *
     * @ORM\Column(name="created_at", type="datetime", nullable=true)
     */
    public $createdAt;

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="modified_at", type="datetime", nullable=false)
     */
    public $modifiedAt;
    
    /**
     * @var integer
     *
     * @ORM\Column(name="confirmed", type="integer", nullable=true)
     */
    public $confirmed = 0;//0 waiting, 1 confirmed (, 2 refused?)

    /**
     * @var \DateTime
     *
     * @ORM\Column(name="confirm_at", type="datetime", nullable=true)
     */
    public $confirmAt;
    
    public function getJson(){
        $result = array(
        	"id"=>$this->id,
            "confirmed"=>$this->confirmed,
            "confirm_at"=>$this->confirmAt==null?"":$this->confirmAt->format("Y-m-d H:i:s"),
            "created_at"=>$this->createdAt==null?"":$this->createdAt->format("Y-m-d H:i:s"),
            "modified_at"=>$this->modifiedAt==null?"":$this->modifiedAt->format("Y-m-d H:i:s"),
        );
        if($this->userFrom!=null) $result["user-from"] = $this->userFrom->getJson();
        if($this->userTo!=null) $result["user-to"] = $this->userTo->getJson();
        return $result;
    }

}
